{extend name="adminblue/base" /}
{block name="resources"/}
<script src="ADMIN_JS/art_dialog.source.js"></script>
<script src="ADMIN_JS/iframe_tools.source.js"></script>
<script src="ADMIN_JS/material_managedialog.js"></script>
<link rel="stylesheet" type="text/css" href="ADMIN_CSS/defau.css">
<style type="text/css">

</style>
{/block}
{block name="main"}
<div class="span1"></div>
<div class="set-style">
	<dl>
		<dt><span style="color:red;margin-right:10px;">*</span>导航名称：</dt>
		<dd><input id="nav_title" type="text" class="input-common" name="title"/></dd>
	</dl>
	<dl>
		<dt>排序号：</dt>
		<dd><input id="sort" type="number" value="0" class="input-common harf" min="0"/></dd>
	</dl>
	<dl>
		<dt><span style="color:red;margin-right:10px;">*</span>链接地址：</dt>
		<dd >
			<label for="url_type1" class="radio inline normal">
				<i class="radio-common selected"><input type="radio" value="0" name="url_type" id="url_type1" checked="checked"/></i>
				<span>商城模块</span>
			</label>
			<label for="url_type2" class="radio inline normal">
				<i class="radio-common"><input type="radio" value="1" name="url_type" id="url_type2" /></i>
				<span>自定义链接</span>
			</label>
		</dd>
	</dl>
	<dl>
		<dt></dt>
		<dd>
			<!-- 默认展示pc端模块 -->
			<select class="select-common" id="shopNavModel">
				<option value="">请选择</option>
				{notempty name="shopNavTemplate"}
				{foreach name="shopNavTemplate" item="vo"}
					{if $vo.use_type eq 1}
					<option value="{$vo.template_url}">{$vo.template_name}</option>
					{/if}
				{/foreach}
				{/notempty}
			</select>
			<span style="display: none;" id="nav_url">
				<input type="text" class="input-common" name="nav_url" />
				<span style="line-height: 28px;color: #999;">如：http://www.niushop.com.cn/</span>
			</span>
		</dd>
	</dl>
	<dl>
		<dt><span style="color:red;margin-left:15px;"></span>所属类型：</dt>
		<dd>
			<label for="navigationtype1" class="radio inline normal">
				<i class="radio-common selected"><input type="radio" value="1" name="navigationtype" id="navigationtype1" checked="checked"/></i>
				<span>PC端</span>
			</label>
			<label for="navigationtype2" class="radio inline normal">
				<i class="radio-common"><input type="radio" value="2" name="navigationtype" id="navigationtype2"/></i>
				<span>手机端</span>
			</label>		
		</dd>
	</dl>
	<dl>
		<dt>是否新窗口打开：</dt>
		<dd>
			<p>
				<input id="is_blank" type="checkbox"  class="checkbox"  />
			</p>
		</dd>
	</dl>
	<dl>
		<dt>是否显示：</dt>
		<dd>
			<p>
				<input id="is_show" type="checkbox"  class="checkbox"  />
			</p>
		</dd>
	</dl>
	<dl>
		<dt>导航图标：</dt>
		<dd>
			<div class="upload-btn-common">
				<div>
					<input class="input-file" name="file_upload" id="uploadImg" type="file" onchange="imgUpload(this);">
					<input type="hidden" id="logo" value="" />
				</div>
				<input type="text" id="text_logo" class="input-common" readonly="readonly" value="" />
				<em>上传</em>
				
				<img id="preview_logo" src="__STATIC__/blue/img/upload-common-select.png" data-src="" data-html="true" data-container="body" data-placement="top" data-trigger="manual"/>

			</div>

			<p class="hint">
				<span>建议使用<i class="important-note">宽86</i>像素-<i class="important-note">高86</i>像素内的<i class="important-note">JPG</i>或<i class="important-note">PNG</i>正方形图片</span>
			</p>
		</dd>
	</dl>
	<dl>
		<dt></dt>
		<dd>
			<button class="btn-common btn-big" onclick="save()">保存</button>
			<button class="btn-common-cancle btn-big" onclick="window.location.href = window.history.go(-1);" >返回</button>
		</dd>
	</dl>
</div>
{/block}
{block name="script"}
<script src="__STATIC__/js/ajax_file_upload.js" type="text/javascript"></script>
<script src="__STATIC__/js/file_upload.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
	$("input[type='radio'][name='navigationtype']").click(function(){
		var type = $(this).val();
		switchUseType(type);
	})
})

function save(){
	var nav_title=$("#nav_title").val();
	var sort=$("#sort").val();
	var type=$("input[name='navigationtype']:checked").val();
	if(nav_title == ''){
		showTip("导航名称不能为空","warning");
		$("#nav_title").focus();
		return false;	
	}
	if(sort=='')$("#sort").val(0);
	var url_type = $("input[name=url_type]:checked").val();
	if(url_type == 0){
	var nav_url=$("#shopNavModel").val();
	var template_name = $("#shopNavModel option:selected").text();
	}else if(url_type == 1){
		var nav_url=$("input[name=nav_url]").val();
		var template_name = '';
	}
	if(nav_url == ''){
		showTip("链接地址不能为空","warning");
		return false;
	}
	var is_blank = $("#is_blank").prop('checked') ? 1 : 0 ;
	var is_show = $("#is_show").prop('checked') ? 1 : 0 ;
	var nav_icon = $("#logo").val();
	$.ajax({
		type:"post",
		url:"{:__URL('ADMIN_MAIN/config/addshopnavigation')}",
		data:{
		'nav_title':nav_title,
		'sort':sort,
		'nav_url':nav_url,
		'type':type,
		'nav_type' : url_type,
		'is_blank' : is_blank,
		'template_name' : template_name,
		'nav_icon' : nav_icon,
		'is_show' : is_show
		},
		success:function(data){
			if (data["code"] > 0) {
				showTip(data["message"],'success');
				location.href=__URL("ADMIN_MAIN/config/shopnavigationlist");
			}else{
				showTip(data["message"],'error');
			}
		}
	});
}

$("#url_type1").click(function(){
	$(".selectric-select-common").show();
	$("#nav_url").hide();
})
$("#url_type2").click(function(){
	$(".selectric-select-common").hide();
	$("#nav_url").show();
})

function imgUpload(event) {
	var fileid = $(event).attr("id");
	var data = { 'file_path' : UPLOADCOMMON };
	var id = $(event).next().attr("id");
	uploadFile(fileid,data,function(res){
		if(res.code){
			$("#"+id).val(res.data);
			$("#text_" + id).val(res.data);
			$("#preview_" + id).attr("data-src",__IMG(res.data));
			showTip(res.message,"success");
		}else{
			showTip(res.message,"error");
		}
	});
}

// 切换
function switchUseType(use_type){
	var shopNavTemplateJson = '{$shopNavTemplateJson}';
	var shopNavTemplateArr = JSON.parse(shopNavTemplateJson);
	var html = '<option value="">请选择</option>';
	for (var i = 0; i < shopNavTemplateArr.length; i++) {
		var item = shopNavTemplateArr[i];
		if(item['use_type'] == use_type){
			html += '<option value="'+item['template_url']+'">'+item['template_name']+'</option>';
		}
	}
	$("#shopNavModel").html(html).selectric({
		maxHeight: 500
	});
}
</script>
{/block}